package com.qt.thread.homework.work1;

import java.util.ArrayList;
import java.util.Random;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author zsf
 * @Date 2023/10/3 23:54
 * @Version 1.0
 */
public class HbThread extends Thread{

    private static double money = 100;
    private static final double MIN = 0.01;
    private static int count = 3;



    public HbThread(String name) {
        super(name);
    }

    @Override
    public void run() {

        synchronized (HbThread.class) {
            if(count == 0){
                System.out.println(Thread.currentThread().getName() + "没抢到红包");
            }else {
                double prize = 0;
                if(count > 1){
                    double item = Math.random() * money;
                    if(item == 0){
                        prize = MIN;
                    }else {
                        if(item > 99.98){
                            prize = 99.98;
                        }else {
                            prize = item;
                        }
                    }
                    prize = prize - MIN;
                    money = money - prize;
                }else {
                    prize = money;
                }

                System.out.println(Thread.currentThread().getName() + "抢到了红包" + prize + "元");
                count--;

            }
        }


    }
}
